package com.seventh.parkingrent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.parkingrent.controller.form.ParkingSpaceAuditForm;
import com.seventh.parkingrent.controller.form.ParkingSpaceFormForFront;
import com.seventh.parkingrent.domain.ParkingSpace;
import com.seventh.parkingrent.dao.ParkingSpaceMapper;
import com.seventh.parkingrent.service.IParkingSpaceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 车位信息表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@Service
@Slf4j
public class ParkingSpaceServiceImpl extends ServiceImpl<ParkingSpaceMapper, ParkingSpace> implements IParkingSpaceService {
    @Resource
    private ParkingSpaceMapper parkingSpaceMapper;

    @Override
    public Integer getNeedAuditParkingNo() {
        QueryWrapper<ParkingSpace> wrapper = new QueryWrapper<>();
        wrapper.eq("state","0");
        List<ParkingSpace> parkingSpaces = parkingSpaceMapper.selectList(wrapper);
        if(null==parkingSpaces){
            return 0;
        }
        return parkingSpaces.size();
    }

    @Override
    public IPage<ParkingSpaceFormForFront> getNeedAuditParking(Integer pageIndex, Integer pageSize) {
        IPage page = new Page(pageIndex, pageSize);
        IPage<ParkingSpaceFormForFront> parkingSpaceIPage = parkingSpaceMapper.selectForForm(page);
        return parkingSpaceIPage;
    }

    @Override
    public Integer updateParkingSpaceAudit(ParkingSpaceAuditForm form) {
        @NotNull Integer parkingSpaceId = form.getParkingSpaceId();
        ParkingSpace parkingSpace = parkingSpaceMapper.selectById(parkingSpaceId);
        parkingSpace.setState(form.getIsaudit());
        parkingSpace.setMessage(form.getMessage());
        parkingSpace.setPropertyManagerGet(form.getPropertyManagerGet());
        parkingSpace.setPlatoformGet(form.getPlatoformGet());
        int insert = parkingSpaceMapper.updateById(parkingSpace);
        return insert;
    }

    @Override
    public List<String> selectParkingSpaceAddr() {

        List<String> parkingSpaceAddrs = parkingSpaceMapper.selectParkingSpaceAddr();
        return parkingSpaceAddrs;
    }

    @Override
    public IPage<ParkingSpaceFormForFront> selectParkingSpaceByObjectLike(String username, String propertyName, String parkingSpaceAddr, Integer pageIndex, Integer pageSize) {
        IPage page = new Page(pageIndex, pageSize);
        IPage<ParkingSpaceFormForFront> parkingSpaceIPage = parkingSpaceMapper.selectParkingSpaceByUsernameLike(page, username,propertyName,parkingSpaceAddr);

        return parkingSpaceIPage;
    }


}
